﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using DoAnASP;

public partial class DangKi : System.Web.UI.Page
{
   // DataService DB = new DataService();
    
   // string chuoiketnoi = ConfigurationManager.ConnectionStrings["QLBH"].ConnectionString;
  //  SqlConnection ketnoi;
    protected void Page_Load(object sender, EventArgs e)
    {

        BUS_NhanVien nv = new BUS_NhanVien();
        DataTable dt = new DataTable();
        dt = nv.LoadQuyen();
        ddlquyen.DataSource = dt.DefaultView;
        
        ddlquyen.DataTextField = dt.Columns[1].ColumnName;
        ddlquyen.DataValueField = dt.Columns[0].ColumnName;
        ddlquyen.DataBind();


    }
    public void LoadCapNhat(DTO_NhanVien nv )
    {
        BUS_NhanVien nv1 = new BUS_NhanVien();
        DTO_NhanVien daonv = new DTO_NhanVien();

        txtDiaChi.Text = nv.Address;
        txtEmail.Text = nv.Email;
        txtHoTen.Text = nv.FullName;
        nv.IDQuyenTruyCap = nv.IDQuyenTruyCap;
        txtMatKhau1.Text = nv.Password;
        txtSDT.Text = nv.NumBerPhone;
        txtTenDN.Text = nv.Username;
    }
    protected void btnDangKy_Click(object sender, ImageClickEventArgs e)
    {

        DTO_NhanVien nv = new DTO_NhanVien();

        nv.Address = txtDiaChi.Text;
        nv.Email = txtEmail.Text;
        nv.FullName = txtHoTen.Text;
        nv.NumBerPhone = txtSDT.Text;
        nv.Password = txtMatKhau1.Text;
        nv.Username = txtTenDN.Text.ToLower().Trim();
        nv.IDQuyenTruyCap = ddlquyen.SelectedIndex;

     
        BUS_NhanVien them = new BUS_NhanVien();
        bool kiemtra = them.KiemTraTonTai(nv);
        try
        {
            if (kiemtra == false) // = false có nghĩa là trong csdl không có tên truy cập trên
            {
                them.DangKyTV(nv);
                Session["MaTB"] = 3;
                Response.Redirect("ThongBao.aspx");
            }
            else

            {
               // rfvThongBaoLoi.Text= "Tên truy cập đẫ được sử dụng";
               // rfvThongBaoLoi.ErrorMessage = 
                Label loiDN = new Label();
                loiDN.Text = "Tên truy cập đẫ được sử dụng";
                pnThongBaoLoi.Controls.Add(loiDN);
                

                
            }
              
        }
        catch (Exception)
        {
            
            throw;
        }
     

        
    }
}